package cn.yhbk.web.modules.manager.Controller;

import cn.hutool.core.bean.BeanUtil;
import cn.yhbk.web.common.api.CommonResult;
import cn.yhbk.web.modules.manager.Pojo.DTO.Sys.SysDto;
import cn.yhbk.web.modules.manager.Pojo.Entity.SysEntity;
import cn.yhbk.web.modules.manager.Pojo.VO.Sys.SysUpdate;
import cn.yhbk.web.modules.manager.Service.SysService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "系统配置接口")
@RestController
@RequestMapping("/sys")
public class SysController {

    @Autowired
    private SysService sysService;

    @ApiOperation("获取系统配置")
    @GetMapping("/getSysList")
    public CommonResult<List<SysDto>> getSysList(){

        return CommonResult.success(sysService.getSysList());
    }

    @ApiOperation("获取某一项系统配置")
    @GetMapping("/getSys/{sysKey}")
    public CommonResult<SysDto> getSysList(@PathVariable("sysKey") String sysKey){
        SysEntity sys_key = sysService.getOne(new QueryWrapper<SysEntity>().eq("sys_key", sysKey));

        return CommonResult.success(BeanUtil.copyProperties(sys_key, SysDto.class));
    }

    @ApiOperation("修改系统配置")
    @PutMapping("/updateSys")
    public CommonResult<String> updateSys(@RequestBody SysUpdate sysUpdate){
        sysService.updateSys(sysUpdate);

        return CommonResult.success("操作成功");
    }

    @ApiOperation("添加系统配置")
    @PostMapping("/addSys")
    public CommonResult addSys(@RequestBody SysUpdate sysUpdate){
        sysService.addSys(sysUpdate);

        return CommonResult.success("操作成功");
    }

}
